<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="../css/css.css" type="text/css" />
		<title>登录</title>
		<script type="text/javascript" src="../js/update.js"></script>
		<script type="text/javascript" src='../js/jquery.min.js'></script>
		<script type="text/javascript" src='../js/main_in.js'></script>
		<script type="text/javascript" charset="utf-8">
// H5 plus事件处理
var as='pop-in';// 默认窗口动画
function plusReady(){
	// 隐藏滚动条
	plus.webview.currentWebview().setStyle({scrollIndicator:'none'});
	// Android处理返回键
	plus.key.addEventListener('backbutton',function(){
		('iOS'==plus.os.name)?plus.nativeUI.confirm('确认退出？', function(e){
			if(e.index>0){
				plus.runtime.quit();
			}
		}, 'HelloH5', ['取消','确定']):(confirm('确认退出？')&&plus.runtime.quit());
	},false);
	compatibleAdjust();
}
if(window.plus){
	plusReady();
}else{
	document.addEventListener('plusready',plusReady,false);
}
// DOMContentLoaded事件处理
var _domReady=false;
document.addEventListener('DOMContentLoaded',function(){
	_domReady=true;
	compatibleAdjust();
},false);
// 兼容性样式调整
var _adjust=false;
function compatibleAdjust(){
	if(_adjust||!window.plus||!_domReady){
		return;
	}
	_adjust=true;
	// iOS平台特效
	if('iOS'==plus.os.name){
		document.getElementById('content').className='scontent';	// 使用div的滚动条
		if(navigator.userAgent.indexOf('StreamApp')>=0){	// 在流应用模式下显示返回按钮
			document.getElementById('back').style.visibility='visible';
		}
	}
	// 预创建二级窗口
//	preateWebviews();
	// 关闭启动界面
		plus.navigator.setStatusBarBackground('#D74B28');
	setTimeout(function(){
		plus.navigator.closeSplashscreen();
	},200);
}
// 处理点击事件
var _openw=null;
/**
 * 点击打开新窗口
 * @param {Object} id	加载的页面地址，也用作窗口标识
 * @param {Object} a	页面动画内心，默认使用全局as设置的值
 * @param {Object} s	是否不显示窗口
 */
function clicked(id,a,s){
	if(_openw){return;}
	a||(a=as);
	_openw=preate[id];
	if(_openw){
		_openw.showded=true;
		_openw.show(a,null,function(){
			_openw=null;//避免快速点击打开多个页面
		});
	}else{
//		var wa=plus.nativeUI.showWaiting();
//		_openw=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'hide'},{preate:true});//复用二级页面
		_openw=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'close'});
		preate[id]=_openw;
		_openw.addEventListener('loaded',function(){//叶面加载完成后才显示
//		setTimeout(function(){//延后显示可避免低端机上动画时白屏
//			wa.close();
			_openw.showded=true;
			s||_openw.show(a,null,function(){
				_openw=null;//避免快速点击打开多个页面
			});
			s&&(_openw=null);//避免s模式下变量无法重置
//		},10);
		},false);
		_openw.addEventListener('hide',function(){
			_openw&&(_openw.showded=true);
			_openw=null;
		},false);
		_openw.addEventListener('close',function(){//页面关闭后可再次打开
			_openw=null;
			preate[id]&&(preate[id]=null);//兼容窗口的关闭
		},false);
	}
}
// 预创建二级页面
var preate={};
function preateWebviews(){
	preateWebivew('plus/webview.html');
	var plist=document.getElementById('plist').children;
	// 由于启动是预创建过多Webview窗口会消耗较长的时间，所以这里限制仅创建5个
	for( var i=0;i<plist.length&&i<2;i++){
		var id=plist[i].id;
		id&&(id.length>0)&&preateWebivew(id);
	}
}
function preateWebivew(id){
	if(!preate[id]){
		var w=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'hide'},{preate:true});
		preate[id]=w;
		w.addEventListener('close',function(){//页面关闭后可再次打开
			_openw=null;
			preate[id]&&(preate[id]=null);//兼容窗口的关闭
		},false);
	}
}
// 清除预创建页面(仅)
function preateClear(){
	for(var p in preate){
		var w=preate[p];
		if(w&&w.showded&&!w.isVisible()){
			w.close();
			preate[p]=null;
		}
	}
}

/////////////
function dologin(){
	var lgname = $("#lgname").val();
	var lgpass = $("#lgpass").val();
	var ischecked = $("input[type='checkbox']").is(':checked');
	var wt=plus.nativeUI.showWaiting();
		$.ajax({
            url : 'http://api.unair.cn/api/UserCL',
            type : "POST",
            data : {
                "Token" : "22e8f734-dae9-494e-a743-4c4a64af4ce2",  
                "Users" : {
                	"LoginName":lgname,
                	"Password":lgpass
                }
            },  
            dataType : 'json',  
            success : function(data) {  
                if(data['success'] == false){
                	wt.close();
					login_error();
                    return false;
                }
                		if(data['user']['ID'] > 0 && data['user']['State'] == 2){
                            
                            
                            if(ischecked == true){
                            	localStorage.setItem("loginname",lgname);   //记住的账号
                            	localStorage.setItem("password",lgpass);    //记住的密码
                            	localStorage.setItem("lgname", data['user']['LoginName']);
                            	localStorage.setItem("uid", data['user']['ID']);
                            	localStorage.setItem("name", data['user']['Name']);
                            	localStorage.setItem("RecommendBy", data['user']['RecommendBy']);
                            	localStorage.setItem("cpid", data['user']['CPID']);
                            	localStorage.setItem("cpname", data['user']['CPName']);
                            	localStorage.setItem("ndid", data['user']['NDID']);
                            	localStorage.setItem("ndname", data['user']['NDName']);
                            }else if(aa == false){
                            	localStorage.setItem("lgname", data['user']['LoginName']);
                                localStorage.setItem("uid", data['user']['ID']);
                            	localStorage.setItem("name", data['user']['Name']);
                            	localStorage.setItem("RecommendBy", data['user']['RecommendBy']);
                            	localStorage.setItem("cpid", data['user']['CPID']);
                            	localStorage.setItem("cpname", data['user']['CPName']);
                            	localStorage.setItem("ndid", data['user']['NDID']);
                            	localStorage.setItem("ndname", data['user']['NDName']);
                            }
                            wt.close();
                             login_ok();
                         }else{
                         	wt.close();
                         	login_error();	
                         }
            },  
            error : function() {
            	wt.close();
            	login_error();	
            }  
       }); 
}
var t = n = 0;
var count = 0;
$(function(){
	count = $(".banner_img").length;
	var storage = window.localStorage;
	var loginname = storage["loginname"];
	var password = storage["password"];
	$("#lgname").val(loginname);
	$("#lgpass").val(password);
	
	$(".banner span").click(function(){
		var i = $(this).attr('class');
		if(i == 'b_1'){
			$(".banner_img").hide()
			$(".banner1").show();
		}
		if(i == 'b_2'){
			$(".banner_img").hide()
			$(".banner2").show();
		}
		$(".banner span").css('background','#fff');
		$(this).css('background','#ddd');
	})
	
								var t=setInterval(function(){
									banner()
								},5000);
});

function banner(){
	n = n >= (count - 1) ? 0 : ++n;
    $(".banner span").eq(n).trigger('click');
}

function do_register(){
	clicked("useradd.html");
}

function login_ok(){
                    			var w=plus.nativeUI.showWaiting("登陆成功");
								w.onclose=function(){
									clearInterval(t);
								}
								var t=setInterval(function(){
									w.setTitle("登陆成功");
									w.close();
									clicked("../index.html")
									clearInterval(t);
								},2000);
}

function login_error(){
                             	var w=plus.nativeUI.showWaiting("用户名密码错误");
								w.onclose=function(){
									clearInterval(t);
								}
								var t=setInterval(function(){
									w.close();
									clearInterval(t);
									w.setTitle("用户名密码错误");
								},1000);
								$("#lgpass").val('');
}

		</script>
	</head>
	<body>
		<div class="banner">
			<img class="banner_img banner2" src="http://insure.unair.cn/images/banner_1.jpg" />
			<img class="banner_img banner1" src="http://insure.unair.cn/images/banner_2.jpg" />
			<span class="b_1"></span>
			<span class="b_2"></span>
		</div>
		<div class="app_head">
            <div class="app_prev"></div>
            <div class="app_head_text">欢&nbsp;&nbsp;&nbsp;&nbsp;迎</div>
            <div class="app_prev"></div>
        </div>
        
        <div class="app_body">
            <div class="main_in_input">
                <div class="main_in_input_img"><img src="../img/icon.png" /></div>
                <div class="main_in_input_text"><input type="text" id="lgname" placeholder="请输入用户名" /></div>
                <!--<input type="hidden" id="number" />-->
            </div>
            <div class="main_in_input">
                <div class="main_in_input_img"><img src="../img/icon_02.png" /></div>
                <div class="main_in_input_text"><input type="password" id="lgpass" placeholder="请输入密码" /></div>
            </div>
            <div class="main_in_input_checkbox">
                <div class="main_in_input_checkbox_img"><input id="ischecked" type="checkbox" checked value="1" /></div>
                <div class="main_in_input_checkbox_text">记住密码</div>
            </div>
            <div class="app_submit"  onclick="dologin()">登&nbsp;录</div>
            <!--<div class="login_foot">
                <div class="login_foot_prev" onclick="do_register()">点击注册</div>
                <div class="login_foot_center">|</div>
                <div class="login_foot_next">找回密码</div>
            </div>-->
            <div class="app_400" >服务热线 : 400-6885666</div>
        </div>
        
<div class="outside_pull"></div>
<img src="../img/loading.gif" class="fade_out_img" id="fade_out_loading" />
	</body>
</html>
